// Copyright (C) 2016 All rights reserved.
// Author: liufeng11@letv.com (Liu Feng)
// Description:

#include "SimilarCharacter.h"
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TBinaryProtocol.h>

#include <iostream>
using namespace std;

using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;


int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("usage:./SiClient <charCode> [ip] [port]\n");
    return 1;
  }

  char *ip = "127.0.0.1";
  int port = 9090;

  if (argc >= 3) ip = argv[2];
  if (argc >= 4) port = atoi(argv[3]);

  boost::shared_ptr<TSocket>socket(new TSocket(ip, port));
  // boost::shared_ptr<TTransport>transport(new TBufferedTransport(socket));
  boost::shared_ptr<TTransport>transport(new TFramedTransport(socket));
  boost::shared_ptr<TProtocol>protocol(new TBinaryProtocol(transport));


  SimilarCharacterClient client(protocol);
  transport->open();

  std::vector<int32_t> r;
  int32_t cc = strtol(argv[1], NULL, 16);
  client.Si(r, cc);
  for (size_t i = 0; i < r.size(); ++i) {
    if(i==0) printf("%04x", r[0]);
    else printf(",%04x", r[i]);
  }
  transport->close();

  return 0;
}

